home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / FWDebug / Include / FWDbgStr.h next >
Encoding:
C/C++ Source or Header  |  1994-04-21  |  5.9 KB  |  236 lines  |  [TEXT/MPS ]

  1. #if !defined(FWDBGSTR_H) && defined(FW_DEBUG)
  2. #define FWDBGSTR_H
  3. //========================================================================================
  4. //
  5. //    File:                FWDbgStr.h
  6. //    Release Version:    $ 1.0d1 $
  7. //
  8. //    Creation Date:        3/28/94
  9. //
  10. //    Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  11. //
  12. //========================================================================================
  13.  
  14. #include <stddef.h>
  15.  
  16. #ifndef FWSTDDEF_H
  17. #include "FWStdDef.h"
  18. #endif
  19.  
  20. #ifdef FW_BUILD_WIN
  21. #include <Windows.h>
  22. #endif
  23.  
  24. //========================================================================================
  25. // CLASS FW_CDebugStream
  26. //========================================================================================
  27.  
  28. class FW_CDebugStream
  29. {
  30. public:
  31.     typedef FW_CDebugStream& (*Manipulator)(FW_CDebugStream &);
  32.  
  33.     friend FW_CDebugStream &EndLine(FW_CDebugStream &);
  34.  
  35.     FW_CDebugStream();
  36.     virtual ~FW_CDebugStream();
  37.         // Destructor
  38.     
  39.     virtual class FW_CDebugStream &Write(const void *data, size_t size) = 0;
  40.         // Does the raw write of the data without any data separator
  41.     
  42.     FW_CDebugStream &WriteChunk(const void *data, size_t size);
  43.         // Write raw data with a data separator
  44.  
  45.     FW_CDebugStream &operator<<(Manipulator function);
  46.         // Execute the manipulator
  47.  
  48.     
  49.     FW_CDebugStream &operator<<(const char *string);
  50.         // Write null terminated char string
  51.         
  52.     FW_CDebugStream &operator<<(const signed char *string);
  53.         // Write null terminated string
  54.         
  55.     FW_CDebugStream &operator<<(const unsigned char *string);
  56.         // Write null terminated string
  57.         
  58.  
  59.     FW_CDebugStream &operator<<(char c);
  60.         // Write character
  61.  
  62.     FW_CDebugStream &operator<<(signed char c);
  63.         // Write signed character
  64.  
  65.     FW_CDebugStream &operator<<(unsigned char c);
  66.         // Write unsigned character
  67.  
  68.     FW_CDebugStream &operator<<(short n);
  69.         // Write short
  70.  
  71.     FW_CDebugStream &operator<<(int n);
  72.         // Write int
  73.  
  74.     FW_CDebugStream &operator<<(long n);
  75.         // Write long
  76.  
  77.     FW_CDebugStream &operator<<(unsigned short n);
  78.         // Write unsigned short
  79.  
  80.     FW_CDebugStream &operator<<(unsigned n);
  81.         // Write unsigned
  82.  
  83.     FW_CDebugStream &operator<<(unsigned long n);
  84.         // Write unsigned long
  85.  
  86.     FW_CDebugStream &operator<<(void *);
  87.         // Write address in hex
  88.  
  89. protected:
  90.     FW_CDebugStream & WriteBase10Number(long n);
  91.         // Write long in base 10
  92.  
  93.     FW_CDebugStream & WriteBase16Number(long n);
  94.         // Write long in base 16
  95.  
  96. private:
  97.     FW_CDebugStream(const FW_CDebugStream& debugStream);
  98.     FW_CDebugStream& operator=(const FW_CDebugStream& debugStream);
  99.         // Don't copy instances of this class.
  100. };
  101.  
  102.  
  103. inline FW_CDebugStream &FW_CDebugStream::operator<<(Manipulator function)
  104. {
  105.     return function(*this);
  106. }
  107.  
  108. inline FW_CDebugStream & FW_CDebugStream::operator<<(const char *string)
  109. {
  110.     return operator<<((const signed char *) string);
  111. }
  112.  
  113. inline FW_CDebugStream & FW_CDebugStream::operator<<(const unsigned char *string)
  114. {
  115.     return operator<<((const signed char *) string);
  116. }
  117.  
  118. inline FW_CDebugStream & FW_CDebugStream::operator<<(char c)
  119. {
  120.     return operator<<((signed char) c);
  121. }
  122.  
  123. inline FW_CDebugStream & FW_CDebugStream::operator<<(unsigned char c)
  124. {
  125.     return operator<<((signed char) c);
  126. }
  127.  
  128. inline FW_CDebugStream & FW_CDebugStream::operator<<(short n)
  129. {
  130.     return operator<<((long) n);
  131. }
  132.  
  133. inline FW_CDebugStream & FW_CDebugStream::operator<<(int n)
  134. {
  135.     return operator<<((long) n);
  136. }
  137.  
  138. inline FW_CDebugStream & FW_CDebugStream::operator<<(unsigned short n)
  139. {
  140.     return operator<<((unsigned long) n);
  141. }
  142.  
  143. inline FW_CDebugStream & FW_CDebugStream::operator<<(unsigned n)
  144. {
  145.     return operator<<((unsigned long) n);
  146. }
  147.  
  148.  
  149. //========================================================================================
  150. // CLASS EndLine
  151. //========================================================================================
  152.  
  153. FW_CDebugStream &EndLine(FW_CDebugStream &);
  154.     // Output end of line character or characters depending on platform
  155.  
  156. //========================================================================================
  157. // CLASS FW_CBufferDebugStream
  158. //========================================================================================
  159.  
  160. class FW_CBufferDebugStream : public FW_CDebugStream
  161. {
  162. public:
  163.     FW_CBufferDebugStream(void * buffer, size_t bufferSize);
  164.         // Constructor
  165.     
  166.     virtual FW_CDebugStream &Write(const void *data, size_t size);
  167.         // Write data
  168.  
  169. private:
  170.     const void * fBuffer;
  171.         // FW_SPlatformPoint to data buffer
  172.  
  173.     const size_t fBufferSize;
  174.         // Size of buffer
  175.  
  176.     size_t fPosition;
  177.         // Next position to write to in buffer
  178.  
  179.     FW_CBufferDebugStream(const FW_CBufferDebugStream& debugStream);
  180.     FW_CBufferDebugStream& operator=(const FW_CBufferDebugStream& debugStream);
  181.         // Don't copy instances of this class.
  182. };
  183.  
  184.  
  185. //========================================================================================
  186. // CLASS FW_CNullDebugStream
  187. //========================================================================================
  188.  
  189. class FW_CNullDebugStream : public FW_CDebugStream
  190. {
  191. public:
  192.     FW_CNullDebugStream();
  193.     virtual ~FW_CNullDebugStream();
  194.  
  195.     virtual FW_CDebugStream &Write(const void *data, size_t size);
  196.         // Write data
  197.  
  198. private:
  199.     FW_CNullDebugStream(const FW_CNullDebugStream& debugStream);
  200.     FW_CNullDebugStream& operator=(const FW_CNullDebugStream& debugStream);
  201.         // Don't copy instances of this class.
  202. };
  203.  
  204.  
  205. //========================================================================================
  206. // CLASS FW_CFileDebugStream
  207. //========================================================================================
  208.  
  209. class FW_CFileDebugStream : public FW_CDebugStream
  210. {
  211. public:
  212.     FW_CFileDebugStream(char *fileName);
  213.         // Constructor
  214.     
  215.     ~FW_CFileDebugStream();
  216.         // Destructor
  217.     
  218.     virtual FW_CDebugStream &Write(const void *data, size_t size);
  219.         // Write data
  220.  
  221. private:
  222. #ifdef FW_BUILD_MAC
  223.     short fMacFileNumber;
  224. #endif
  225. #ifdef FW_BUILD_WIN
  226.     HFILE fWinFileHandle;
  227. #endif
  228.  
  229.     FW_CFileDebugStream(const FW_CFileDebugStream& debugStream);
  230.     FW_CFileDebugStream& operator=(const FW_CFileDebugStream& debugStream);
  231.         // Don't copy instances of this class.
  232. };
  233.  
  234.  
  235. #endif
  236.